﻿using Microsoft.AspNetCore.Mvc;
using MediatR;
using RabbitTeacebillty.API.Read.Application.Command;
using Infrastructure;
using Domain;

namespace RabbitTeacebillty.API.Read.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IMediator _mediator;
        public UserController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 用户登录接口
        /// </summary>
        /// <param name="command">登录请求命令</param>
        /// <returns>登录结果</returns>
        [HttpPost]
        public async Task<ApiResult<User>> Login([FromBody] UserQueryCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 用户注册接口
        /// </summary>
        /// <param name="command">注册请求命令</param>
        /// <returns>新用户ID</returns>
        [HttpPost]
        public async Task<ApiResult<int>> Register([FromBody] RegisterUserCommand command)
        {
            return await _mediator.Send(command);
        }
    }
} 